package com.pzhuweb.sgblog.controller;

import com.pzhuweb.sgblog.domain.dto.AddUserDto;
import com.pzhuweb.sgblog.domain.dto.UserDto;
import com.pzhuweb.sgblog.domain.dto.UserStatusDto;
import com.pzhuweb.sgblog.domain.utils.ResponseResult;
import com.pzhuweb.sgblog.service.SystemUserService;
import org.springframework.web.bind.annotation.*;
import reactor.util.annotation.Nullable;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 鄧浩奇
 * @classname SystemUserController
 * @description
 * @since 2023/8/18 17:50
 **/

@RestController
@RequestMapping("/system/user")
public class SystemUserController {

    @Resource
    private SystemUserService systemUserService;

    @GetMapping("/list")
    public ResponseResult<?> getUserList(
            Integer pageNum,
            Integer pageSize,
            String userName,
            @Nullable @RequestParam(value = "phonenumber") String phoneNumber,
            Integer status
    ) {
        return systemUserService.getUserList(pageNum, pageSize, userName, phoneNumber, status);
    }

    @GetMapping("/{id}")
    public ResponseResult<?> getUserInfo(@PathVariable("id") Long id) {
        return systemUserService.getUserInfo(id);
    }

    @PutMapping()
    public ResponseResult<?> updateUser(@RequestBody UserDto userDto) {
        return systemUserService.updateUser(userDto);
    }

    /*
    * 修改状态
    * */
    @PutMapping("/changeStatus")
    public ResponseResult<?> changeStatus(@RequestBody UserStatusDto statusDto) {
        return systemUserService.changeStatus(statusDto);
    }

    /*
    * 新增角色
    * */
    @PostMapping()
    public ResponseResult<?> addUser(@RequestBody AddUserDto addUserDto) {
        return systemUserService.addUser(addUserDto);
    }

    /*
    * 删除用户
    * */
    @DeleteMapping("/{id}")
    public ResponseResult<?> deleteUser(@PathVariable("id") List<Long> id) {
        return systemUserService.deleteUser(id);
    }

}
